home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------------
- // Listing 1. Creating a four-faced polyhedron
- //-------------------------------------------------------------------
-
- TQ3ColorRGB polyhedronColor;
- TQ3PolyhedronData polyhedronData;
- TQ3GeometryObject polyhedron;
- TQ3Vector3D normal;
-
- static TQ3Vertex3D vertices[7] = {
- { { -1.0, 1.0, 0.0 }, NULL },
- { { -1.0, -1.0, 0.0 }, NULL },
- { { 0.0, 1.0, 1.0 }, NULL },
- { { 0.0, -1.0, 1.0 }, NULL },
- { { 2.0, 1.0, 1.0 }, NULL },
- { { 2.0, -1.0, 0.0 }, NULL },
- { { 0.0, -1.0, 1.0 }, NULL }
- };
- TQ3PolyhedronTriangleData triangles[4] = {
- { /* Face 0 */
- { 0, 1, 2 }, /* vertexIndices */
- kQ3PolyhedronEdge01 | kQ3PolyhedronEdge20, /* edgeFlag */
- NULL /* triangleAttributeSet */
- },
- { /* Face 1 */
- { 1, 3, 2 },
- kQ3PolyhedronEdge01 | kQ3PolyhedronEdge12,
- NULL
- },
- { /* Face 2 */
- { 2, 3, 4 },
- kQ3PolyhedronEdgeAll,
- NULL
- },
- { /* Face 3 */
- { 6, 5, 4 },
- kQ3PolyhedronEdgeAll,
- NULL
- }
- };
-
- /* Set up vertices, edges, and triangular faces. */
- polyhedronData.numVertices = 7;
- polyhedronData.vertices = vertices;
- polyhedronData.numEdges = 0;
- polyhedronData.edges = NULL;
- polyhedronData.numTriangles = 4;
- polyhedronData.triangles = triangles;
-
- /* Inherit the attribute set from the current state. */
- polyhedronData.polyhedronAttributeSet = NULL;
-
- /* Put a normal on the first vertex. */
- Q3Vector3D_Set(&normal, -1, 0, 1);
- Q3Vector3D_Normalize(&normal, &normal);
- vertices[0].attributeSet = Q3AttributeSet_New();
- Q3AttributeSet_Add(vertices[0].attributeSet, kQ3AttributeTypeNormal,
- &normal);
-
- /* Same normal on the second. */
- vertices[1].attributeSet =
- Q3Shared_GetReference(vertices[0].attributeSet);
-
- /* Different normal on the third. */
- Q3Vector3D_Set(&normal, -0.5, 0.0, 1.0);
- Q3Vector3D_Normalize(&normal, &normal);
- vertices[2].attributeSet = Q3AttributeSet_New();
- Q3AttributeSet_Add(vertices[2].attributeSet, kQ3AttributeTypeNormal,
- &normal);
- /* Same normal on the fourth. */
- vertices[3].attributeSet =
- Q3Shared_GetReference(vertices[2].attributeSet);
-
- /* Put a color on the third triangle. */
- triangles[3].triangleAttributeSet = Q3AttributeSet_New();
- Q3ColorRGB_Set(&polyhedronColor, 0, 0, 1);
- Q3AttributeSet_Add(triangles[3].triangleAttributeSet,
- kQ3AttributeTypeDiffuseColor, &polyhedronColor);
-
- /* Create the polyhedron object. */
- polyhedron = Q3Polyhedron_New(&polyhedronData);
-
- // ... /* Dispose of attributes created and referenced. */
-
-
- //-------------------------------------------------------------------
- // Listing 2. Using an edge list to specify the edges of a polyhedron
- //-------------------------------------------------------------------
-
- polyhedronData.numEdges = 8;
- polyhedronData.edges = malloc(8 * sizeof(TQ3PolyhedronEdgeData));
-
- polyhedronData.edges[0].vertexIndices[0] = 0;
- polyhedronData.edges[0].vertexIndices[1] = 1;
- polyhedronData.edges[0].triangleIndices[0] = 0;
- polyhedronData.edges[0].triangleIndices[1] = kQ3ArrayIndexNULL;
- polyhedronData.edges[0].edgeAttributeSet = NULL;
-
- polyhedronData.edges[1].vertexIndices[0] = 2;
- polyhedronData.edges[1].vertexIndices[1] = 0;
- polyhedronData.edges[1].triangleIndices[0] = 0;
- polyhedronData.edges[1].triangleIndices[1] = kQ3ArrayIndexNULL;
- polyhedronData.edges[1].edgeAttributeSet = NULL;
-
- polyhedronData.edges[2].vertexIndices[0] = 1;
- polyhedronData.edges[2].vertexIndices[1] = 3;
- polyhedronData.edges[2].triangleIndices[0] = 1;
- polyhedronData.edges[2].triangleIndices[1] = kQ3ArrayIndexNULL;
- polyhedronData.edges[2].edgeAttributeSet = NULL;
-
- polyhedronData.edges[3].vertexIndices[0] = 3;
- polyhedronData.edges[3].vertexIndices[1] = 2;
- polyhedronData.edges[3].triangleIndices[0] = 1;
- polyhedronData.edges[3].triangleIndices[1] = 2;
- polyhedronData.edges[3].edgeAttributeSet = NULL;
-
- //... /* Specify the rest of the edges. */
-
-
- //-------------------------------------------------------------------
- // Listing 3. Creating a mesh
- //-------------------------------------------------------------------
-
- static TQ3Vertex3D vertices[7] = {
- { { -1.0, 1.0, 0.0 }, NULL },
- { { -1.0, -1.0, 0.0 }, NULL },
- { { 0.0, 1.0, 1.0 }, NULL },
- { { 0.0, -1.0, 1.0 }, NULL },
- { { 2.0, 1.0, 1.0 }, NULL },
- { { 2.0, -1.0, 0.0 }, NULL },
- { { 0.0, -1.0, 1.0 }, NULL },
- };
- TQ3MeshVertex meshVertices[7], tmp[4];
- TQ3GeometryObject mesh;
- TQ3MeshFace face01, face2, face3;
- TQ3AttributeSet faceAttributes;
- unsigned long i;
- TQ3ColorRGB color;
- TQ3Vector3D normal;
-
- /* Add normals to some of the vertices. */
- vertices[0].attributeSet = Q3AttributeSet_New();
- Q3Vector3D_Set(&normal, -1, 0, 1);
- Q3Vector3D_Normalize(&normal, &normal);
- Q3AttributeSet_Add(vertices[0].attributeSet, kQ3AttributeTypeNormal,
- &normal);
-
- vertices[1].attributeSet =
- Q3Shared_GetReference(vertices[0].attributeSet);
-
- vertices[2].attributeSet = Q3AttributeSet_New();
- Q3Vector3D_Set(&normal, -0.5, 0.0, 1.0);
- Q3Vector3D_Normalize(&normal, &normal);
- Q3AttributeSet_Add(vertices[2].attributeSet, kQ3AttributeTypeNormal,
- &normal);
-
- vertices[3].attributeSet =
- Q3Shared_GetReference(vertices[2].attributeSet);
-
- /* Create the mesh. */
- mesh = Q3Mesh_New();
-
- /* Create the mesh vertices. */
- for (i = 0; i < 7; i++) {
- meshVertices[i] = Q3Mesh_VertexNew(mesh, &vertices[i]);
- }
-
- /* Create a quad equal to the first two triangles in the polyhedron. */
- tmp[0] = meshVertices[0];
- tmp[1] = meshVertices[1];
- tmp[2] = meshVertices[3];
- tmp[3] = meshVertices[2];
- face01 = Q3Mesh_FaceNew(mesh, 4, tmp, NULL);
-
- /* Create other faces. */
- tmp[0] = meshVertices[2];
- tmp[1] = meshVertices[3];
- tmp[2] = meshVertices[4];
- face2 = Q3Mesh_FaceNew(mesh, 3, tmp, NULL);
-
- tmp[0] = meshVertices[6];
- tmp[1] = meshVertices[5];
- tmp[2] = meshVertices[4];
- face3 = Q3Mesh_FaceNew(mesh, 3, tmp, NULL);
-
- /* Add an attribute set to the last face. */
- faceAttributes = Q3AttributeSet_New();
- Q3ColorRGB_Set(&color, 0, 0, 1);
- Q3AttributeSet_Add(faceAttributes, kQ3AttributeTypeDiffuseColor, &color);
- Q3Mesh_SetFaceAttributeSet(mesh, face3, faceAttributes);
-